package com.yanqu.road.server.cmd.player;

import com.yanqu.road.pb.activity.OldPlayerReturnProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.Protocol;

import java.util.List;

/**
 * @author ：zfr
 * @date ：2021/12/7 15:55
 */
@Cmd(code = CrossProtocol.C_CROSS_GET_OTHER_RETURN_ROLE_INFO, desc = "跨服获取其他角色信息")
public class CrossGetReturnRoleInfoCmd extends CrossCommand {
    private List<Long> serverIdList;
    private String openId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        OldPlayerReturnProto.GetOtherReturnRoleInfoReqToCrossMsg msg = OldPlayerReturnProto.GetOtherReturnRoleInfoReqToCrossMsg.parseFrom(packet.getBytes());
        serverIdList = msg.getGoalServerIdList();
        openId = msg.getOpenId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        for (Long goalServerId : serverIdList) {
            OldPlayerReturnProto.GetOtherReturnRoleInfoReqToServerMsg.Builder reqMsg = OldPlayerReturnProto.GetOtherReturnRoleInfoReqToServerMsg.newBuilder();
            reqMsg.setOriServerId(serverId);
            reqMsg.setOriPlayerId(packet.getPlayerId());
            reqMsg.setOpenId(openId);
            YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.S_CROSS_GET_RETURN_ROLE_INFO, reqMsg);
            MessageHelper.sendPacket(goalServerId, 0, pbMsg);
        }
    }

    @Override
    public void sendData() {

    }
}
